using System;

namespace PostSharp4Spring
{
    /// <summary>
    /// Custom attribute that, when applied on a Spring-configurable class,
    /// specifies the object name.
    /// </summary>
    /// <remarks>
    /// This custom attribute is useful on classes <i>derived</i> from classes
    /// decorated with <see cref="ConfigurableAttribute"/>, because the
    /// configurable character of a class is inherited, but the name is not.
    /// </remarks>
    [AttributeUsage( AttributeTargets.Class, AllowMultiple = false, Inherited = false )]
    public sealed class ObjectNameAttribute : Attribute
    {
        private readonly string name;

        /// <summary>
        /// Specifies the object name of a class.
        /// </summary>
        /// <param name="name">Object name.</param>
        public ObjectNameAttribute( string name )
        {
            this.name = name;
        }

        /// <summary>
        /// Gets the object name.
        /// </summary>
        public string Name { get { return name; } }

        /// <summary>
        /// Determines if the current custom attribute has the
        /// default (and useless, that could be ignored) value.
        /// </summary>
        /// <returns><b>true</b> if the current custom attribute instance
        /// can be ignored, otherwise <b>false</b>.</returns>
        public override bool IsDefaultAttribute()
        {
            return string.IsNullOrEmpty( this.name );
        }
    }
}